package zozopo.background.operator;

import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;

import org.apache.struts2.interceptor.SessionAware;

import zozopo.background.operator.operations.OperatorOS;
import zozopo.background.operator.operations.OperatorTB;
import zozopo.operations.comm.DictionaryOS;
import zozopo.operations.comm.DictionaryTB;
import zozopo.user.operations.UserOS;
import zozopo.user.operations.UserTB;

import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionSupport;

public class PreModifyLimitedflagAction extends ActionSupport implements Action,SessionAware{
	
	
	//传入参数
	private String email = "";
	
	private Map<Object, Object> session;
	
	//传出参数
	private OperatorTB operator;
	Map<String, DictionaryTB> dictionaryMap;
	Map<String,String> limitFlag;
	
	public void setSession(Map arg0) {
		// TODO Auto-generated method stub
		session = arg0;
	}
	
	public String execute(){
			
		
			
			OperatorOS operatorOS = new OperatorOS();
			
			DictionaryOS dictionaryOS = new DictionaryOS(operatorOS.getConn());
			dictionaryMap = dictionaryOS.getDictionaryCodeMapByKind("MANUAL.OPERATOR.LIMITFLAG");
			operator = operatorOS.getInfoByEmail(email);
			limitFlag = new  HashMap<String,String>();
			for(Entry entry:dictionaryMap.entrySet()){
				DictionaryTB dictionary = (DictionaryTB)entry.getValue();
				limitFlag.put(dictionary.getDictionary_value(), UserOS.flagLeveForCheckBox(operator.getLimitedflag_operator(), Integer.parseInt(dictionary.getDictionary_value()), 1));
			}
			//rowNum = userOS.getRowNumForSearchStr(searchStr);
			
			operatorOS.releaseConnection();
			
			
			
			return SUCCESS;
			
	}
	
	public void validate() {
		//权限处理
	
		OperatorTB operator = (OperatorTB)session.get("operatorInfo"); 
	
		if(operator == null){
			addFieldError("errormessage",getText("operator.timeoutornotlogin"));
			return ; 
		} 
		if(!OperatorOS.operatorFlagLeve(operator, 17, 1)){
			
			addFieldError("errormessage","权限不足");
			return ; 
		}//*/
		
	}

	

	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	

	public Map<String, DictionaryTB> getDictionaryMap() {
		return dictionaryMap;
	}

	public void setDictionaryMap(Map<String, DictionaryTB> dictionaryMap) {
		this.dictionaryMap = dictionaryMap;
	}

	public Map<String, String> getLimitFlag() {
		return limitFlag;
	}

	public void setLimitFlag(Map<String, String> limitFlag) {
		this.limitFlag = limitFlag;
	}

	public OperatorTB getOperator() {
		return operator;
	}

	public void setOperator(OperatorTB operator) {
		this.operator = operator;
	}
}
